Again, for your convenience, you can load the data for this exercise using the following code:

library(dplyr)
library(haven)

gp_covid <- 
  read_sav(
    "./data/ZA5667_v1-1-0.sav"
  ) %>% 
  sjlabelled::set_na(na = c(-1:-99, 97))

1

Plot 4 bar plots of 4 variables of your choice in two rows and two columns.
You have to use the par() function in combination with its mfrow option.
tab_1 <- table(gp_covid$hzcy001a)
tab_2 <- table(gp_covid$hzcy002a)
tab_3 <- table(gp_covid$hzcy003a)
tab_4 <- table(gp_covid$hzcy004a)

par(mfrow = c(2, 2))
barplot(tab_1)
barplot(tab_2)
barplot(tab_3)
barplot(tab_4)

That’s interesting. One may wonder what the median is in each of these distributions. You know what’s perfect for visualizing this statistic? Boxplots!

2

Use the same plotting approach, but change the barplot to a boxplot using boxplot().
Creating the tables beforehand is not needed anymore.
par(mfrow = c(2, 2))
boxplot(gp_covid$hzcy001a)
boxplot(gp_covid$hzcy002a)
boxplot(gp_covid$hzcy003a)
boxplot(gp_covid$hzcy004a)

3

Store the boxplots from the previous exercises combined in one png image.
The function for storing base R graphics as png is png() with the filename as argument.
png("Boxlots.png")
par(mfrow = c(2, 2))
boxplot(gp_covid$hzcy001a)
boxplot(gp_covid$hzcy002a)
boxplot(gp_covid$hzcy003a)
boxplot(gp_covid$hzcy004a)
dev.off()
## png 
##   2

Before we later start with the other exercises, you may want to consider to clean your graphics device with dev.off()

dev.off()
## null device 
##           1